package org.groovymud.shell.security.loginsteps;

import static org.groovymud.shell.security.loginsteps.CallBackDelegate.createCallbackArray;

import java.io.IOException;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.FailedLoginException;

import org.groovymud.object.alive.Player;
import org.groovymud.object.registry.MudObjectAttendant;
import org.groovymud.object.registry.Registry;
import org.groovymud.shell.security.callbacks.ActionCallback;
import org.groovymud.shell.security.callbacks.ActionType;
import org.groovymud.shell.security.MudLoginModuleData;

public class LoadPlayer extends ActionLoginStep {

    public LoadPlayer(Registry registry, MudObjectAttendant objectLoader) {
        super(registry, objectLoader);
    }

    @Override
	public void execute(MudLoginModuleData data) throws IOException, UnsupportedCallbackException, FailedLoginException {
		Callback[] cb;
        ActionCallback loadCallback = new ActionCallback(data.getUsername(), ActionType.LOAD, attendant, registry);
		cb = createCallbackArray(loadCallback);
		data.getCallbackHandler().handle(cb);
		data.setPlayer(loadCallback.getPlayer());
		getNextStep().execute(data);
	}

}
